import { Controller } from "../../mvc/core/Controller";
import { IPlayerInfoController } from "./interfaces/IPlayerInfoController";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { PlayerModule } from "../../../modules/PlayerModule";
import { GModuleEvent } from "../mvc/GModuleEvent";
import { SLookupPlayerReply } from "../../../Message/Game/SLookupPlayerReply";
import { LookupPlayerData } from "../view/player/LookupPlayerData";
import { ExperienceConfig } from "../resource/ExperienceConfig";
import { SPlayerItemUpdate } from "../../../Message/Game/SPlayerItemUpdate";
import { ItemData } from "../resource/info/ItemData";
import { SecondCareerUtil } from "../view/secondCareer/util/SecondCareerUtil";
import { PlayerEqStrengthInfo } from "../view/player/equip/PlayerEqStrengthInfo";
import { EquipmentUtil } from "../view/common/util/EquipmentUtil";
import { SArenaCrossPlayerInfo } from "../../../Message/Public/SArenaCrossPlayerInfo";
import { SWrestlePlayerInfo } from "../../../Message/Public/SWrestlePlayerInfo";
import { DataEvent } from "../events/DataEvent";
import { SEntityId } from "../../../Message/Public/SEntityId";
import { GameProxy } from "../mvc/GameProxy";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { IPlayerModule } from "../../../modules/interfaces/IPlayerModule";
type int = number;
//class PlayerInfoController
    
    export  class PlayerInfoController extends Controller implements IPlayerInfoController
    {
        constructor()
        {
            
            super();NetDispatcher.addCmdListener(ServerCommand.PlayerInfoReply, this.onPlayerInfoMsg);
            NetDispatcher.addCmdListener(ServerCommand.ArenaCrossPlayerInfo, this.onArenaCrossPlayerInfo);
            NetDispatcher.addCmdListener(ServerCommand.WrestlePlayerInfo, this.onWrestlePlayerInfo);
            Dispatcher.addEventListener(EventName.playerMenuLookPlayerInfo, this.viewHandler);
            Dispatcher.addEventListener(EventName.PlayerInfo_view, this.viewHandler);
            Dispatcher.addEventListener(EventName.Role_LookupRune, this.onRoleLookupRuneHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._playerModule == null) 
            {
                this._playerModule = new PlayerModule();
            }
            return this._playerModule;
        }

        public viewPlayerInfo(arg1: int): void
        {
            return;
        }

        /* internal  */onPlayerInfoMsg(arg1: Object=null): void
        {
            var loc1=null;
            var loc2=NaN;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc8=0;
            var loc9=0;
            var loc10=null;
            var loc11=null;
            if (this._isLookUp) 
            {
                this.initView();
                if (this._playerModule) 
                {
                    this._playerModule.mode = GModuleEvent.Mode_Other;
                }
            }
            if (this._playerModule && this._isLookUp) 
            {
                this._isLookUp = false;
                loc1 = arg1 as SLookupPlayerReply;
                LookupPlayerData.msg = loc1;
                this._playerModule.updateAttr(loc1.fightAttributeFinal, loc1.fightAttributeBase, loc1.miniPlayer.careerEnable);
                this._playerModule.updateHeadInfo(loc1.miniPlayer.name, loc1.miniPlayer.careerEnable, loc1.miniPlayer.level, loc1.miniPlayer.camp, loc1.honour, loc1.guildName, loc1.miniPlayer.sex, loc1.playerMarry);
                this._playerModule.setLifeValue(loc1.fightAttributeFinal.maxLife, loc1.life);
                this._playerModule.setMagicValue(loc1.fightAttributeFinal.maxMana, loc1.mana);
                this._playerModule.setFighting(loc1.fight.toString());
                this._playerModule.updateSuitPanel();
                this._playerModule.updateWuXingInfo(LookupPlayerData.wuxingInfo, GModuleEvent.Mode_Other);
                this._playerModule.updateMedal();
                this._playerModule.updateUploadAvatar(loc1.miniPlayer.photo);
                this._playerModule.updateRuneFight(loc1.runeFight.toString());
                loc2 = ExperienceConfig.instance.getValueByLevel(loc1.miniPlayer.level);
                this._playerModule.setExperienceValue(loc2, loc1.experience);
                loc4 = (loc3 = loc1.playerItemUpdates).length;
                loc5 = [];
                loc6 = [];
                loc7 = 0;
                loc8 = cache.pack.rolePackCache.sbag.capacity;
                loc7 = 0;
                while (loc7 < loc8) 
                {
                    loc5.push(null);
                    loc6.push(null);
                    ++loc7;
                }
                loc7 = 0;
                while (loc7 < loc4) 
                {
                    if ((loc10 = loc3[loc7] as SPlayerItemUpdate).playerItem) 
                    {
                        loc11 = new ItemData(loc10.playerItem);
                        loc5[(loc10.posIndex - 1)] = loc11;
                        if (loc1.secondCareer != 0) 
                        {
                            loc6[(loc10.posIndex - 1)] = SecondCareerUtil.getSecondCareerItemData(loc1.miniPlayer.career, loc1.secondCareer, loc11);
                        }
                    }
                    ++loc7;
                }
                PlayerEqStrengthInfo.otherEquipments = loc5;
                PlayerEqStrengthInfo.otherJewelTarget = loc1.jewelTarget;
                PlayerEqStrengthInfo.otherEquipmentsSecondCareer = loc6;
                this._playerModule.updateOtherEquipments();
                this._playerModule.setEquipments(loc5, loc1.miniPlayer.career, loc6, loc1.secondCareer, loc1.miniPlayer.camp, loc1.miniPlayer.sex, loc1.wuxingFightAttribute.wuxin, loc1.fashionState, loc1.wingState, loc1.fashionWeaponState, loc1.surroundState, loc1.waistBeltState, loc1.elfState);
                this._playerModule.updateFashionJewelInfo(loc1.fashionJewelInfo, loc1.miniPlayer.level);
                this._playerModule.updateFashionFlyLv(cache.wardrobe.dealFlyLevel(loc1.flyLevel), loc1.miniPlayer.level);
                this._playerModule.vipInfoUpdate(loc1.miniPlayer.VIP);
                this._playerModule.setAcupointInfo();
                this._playerModule.updateTitle(loc1.titleName);
                this._playerModule.updateRuneInfo(loc1.runesInfo, loc1.miniPlayer.career, loc1.miniPlayer.careerEnable);
                this._playerModule.updateFabaoData(loc1.playerAmuletItemUpdate, loc1.miniPlayer.sex);
                loc9 = loc1.fightSpiritLevel > 0 ? 1 : 0;
                this._playerModule.showFightSpirit(loc9);
                if (loc1.miniPlayer.career != loc1.miniPlayer.careerEnable) 
                {
                    this._playerModule.updateFightSpirit(EquipmentUtil.getCurRolePackEquipsData(loc6), loc1.fightSpiritLevel, loc1.fightSpiritBreakLevel);
                }
                else 
                {
                    this._playerModule.updateFightSpirit(EquipmentUtil.getCurRolePackEquipsData(loc5), loc1.fightSpiritLevel, loc1.fightSpiritBreakLevel);
                }
                if (view.isHide) 
                {
                    view.show();
                }
                else 
                {
                    this._playerModule.checkTabBar();
                    this._playerModule.changeTabBarByIndex(0);
                }
            }
            return;
        }

        /* internal  */onArenaCrossPlayerInfo(arg1: SArenaCrossPlayerInfo): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            var loc10=0;
            var loc11=null;
            this.initView();
            if (this._playerModule) 
            {
                this._playerModule.mode = GModuleEvent.Mode_ArenaCross;
            }
            if (this._playerModule) 
            {
                LookupPlayerData.arenaCrossMsg = arg1;
                this._playerModule.updateAttr(arg1.fightAttribute, arg1.fightAttribute, arg1.miniPlayer.careerEnable);
                this._playerModule.updateHeadInfo(arg1.miniPlayer.name, arg1.miniPlayer.careerEnable, arg1.miniPlayer.level, arg1.miniPlayer.camp, 0, "", arg1.miniPlayer.sex, null);
                this._playerModule.setLifeValue(arg1.fightAttribute.maxLife, arg1.fightAttribute.maxLife);
                this._playerModule.setMagicValue(arg1.fightAttribute.maxMana, arg1.fightAttribute.maxMana);
                this._playerModule.setFighting(arg1.miniPlayer.warfare.toString());
                this._playerModule.updateSuitPanel();
                this._playerModule.updateWuXingInfo(LookupPlayerData.wuxingInfo, GModuleEvent.Mode_Other);
                this._playerModule.updateUploadAvatar(arg1.miniPlayer.photo);
                loc1 = ExperienceConfig.instance.getValueByLevel(arg1.miniPlayer.level);
                this._playerModule.setExperienceValue(loc1, 0);
                loc2 = arg1.equips;
                loc3 = loc2.length;
                loc4 = [];
                loc5 = [];
                loc6 = 0;
                loc7 = cache.pack.rolePackCache.sbag.capacity;
                loc6 = 0;
                while (loc6 < loc7) 
                {
                    loc4.push(null);
                    loc5.push(null);
                    ++loc6;
                }
                loc6 = 0;
                while (loc6 < loc3) 
                {
                    if ((loc9 = loc2[loc6] as SPlayerItemUpdate).playerItem) 
                    {
                        loc11 = new ItemData(loc9.playerItem);
                        loc4[(loc9.posIndex - 1)] = loc11;
                    }
                    loc10 = 0;
                    if (arg1.miniPlayer.careerEnable != arg1.miniPlayer.career) 
                    {
                        loc10 = arg1.miniPlayer.careerEnable;
                    }
                    if (loc10 != 0) 
                    {
                        loc5[(loc9.posIndex - 1)] = SecondCareerUtil.getSecondCareerItemData(arg1.miniPlayer.career, loc10, loc11);
                    }
                    ++loc6;
                }
                PlayerEqStrengthInfo.otherEquipments = loc4;
                PlayerEqStrengthInfo.otherJewelTarget = arg1.jewelTarget;
                this._playerModule.updateOtherEquipments();
                this._playerModule.setEquipments(loc4, arg1.miniPlayer.career, loc5, 0, arg1.miniPlayer.camp, arg1.miniPlayer.sex, arg1.wuxing.wuxin, false, false);
                this._playerModule.updateFashionJewelInfo(arg1.fashionJewelInfo, arg1.miniPlayer.level);
                this._playerModule.updateFashionFlyLv(cache.wardrobe.dealFlyLevel(arg1.flyLevel), arg1.miniPlayer.level);
                this._playerModule.vipInfoUpdate(arg1.miniPlayer.VIP);
                this._playerModule.updateByPetInfo(arg1.petInfo);
                this._playerModule.updateByArenaCrossBattle(arg1.miniPlayer, arg1.battlePlans);
                loc8 = arg1.fightSpiritLevel > 0 ? 1 : 0;
                this._playerModule.showFightSpirit(loc8);
                this._playerModule.updateFightSpirit(EquipmentUtil.getCurRolePackEquipsData(loc4), arg1.fightSpiritLevel, arg1.fightSpiritBreakLevel);
                this._playerModule.updateTitle();
                view.show();
                if (!view.isHide) 
                {
                    this._playerModule.checkTabBar();
                    this._playerModule.changeTabBarByIndex(0);
                }
            }
            return;
        }

        /* internal  */onWrestlePlayerInfo(arg1: SWrestlePlayerInfo): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            var loc10=0;
            var loc11=null;
            this.initView();
            if (this._playerModule) 
            {
                this._playerModule.mode = GModuleEvent.Mode_Wrestle;
            }
            if (this._playerModule) 
            {
                LookupPlayerData.wrestleMsg = arg1;
                this._playerModule.updateAttr(arg1.fightAttribute, arg1.fightAttribute, arg1.miniPlayer.careerEnable);
                this._playerModule.updateHeadInfo(arg1.miniPlayer.name, arg1.miniPlayer.careerEnable, arg1.miniPlayer.level, arg1.miniPlayer.camp, 0, "", arg1.miniPlayer.sex, null);
                this._playerModule.setLifeValue(arg1.fightAttribute.maxLife, arg1.fightAttribute.maxLife);
                this._playerModule.setMagicValue(arg1.fightAttribute.maxMana, arg1.fightAttribute.maxMana);
                this._playerModule.setFighting(arg1.miniPlayer.warfare.toString());
                this._playerModule.updateSuitPanel();
                this._playerModule.updateWuXingInfo(LookupPlayerData.wuxingInfoWrestle, GModuleEvent.Mode_Wrestle);
                this._playerModule.updateRuneFight(arg1.runeFight.toString());
                this._playerModule.updateUploadAvatar(arg1.miniPlayer.photo);
                loc1 = ExperienceConfig.instance.getValueByLevel(arg1.miniPlayer.level);
                this._playerModule.setExperienceValue(loc1, 0);
                loc2 = arg1.equips;
                loc3 = loc2.length;
                loc4 = [];
                loc5 = [];
                loc6 = 0;
                loc7 = cache.pack.rolePackCache.sbag.capacity;
                loc6 = 0;
                while (loc6 < loc7) 
                {
                    loc4.push(null);
                    loc5.push(null);
                    ++loc6;
                }
                loc6 = 0;
                while (loc6 < loc3) 
                {
                    if ((loc9 = loc2[loc6] as SPlayerItemUpdate).playerItem) 
                    {
                        loc11 = new ItemData(loc9.playerItem);
                        loc4[(loc9.posIndex - 1)] = loc11;
                    }
                    loc10 = 0;
                    if (arg1.miniPlayer.careerEnable != arg1.miniPlayer.career) 
                    {
                        loc10 = arg1.miniPlayer.careerEnable;
                    }
                    if (loc10 != 0) 
                    {
                        loc5[(loc9.posIndex - 1)] = SecondCareerUtil.getSecondCareerItemData(arg1.miniPlayer.career, loc10, loc11);
                    }
                    ++loc6;
                }
                PlayerEqStrengthInfo.otherEquipments = loc4;
                PlayerEqStrengthInfo.otherJewelTarget = arg1.jewelTarget;
                this._playerModule.updateOtherEquipments();
                this._playerModule.setEquipments(loc4, arg1.miniPlayer.career, loc5, 0, arg1.miniPlayer.camp, arg1.miniPlayer.sex, 0, false, false);
                this._playerModule.updateFashionJewelInfo(arg1.fashionJewelInfo, arg1.miniPlayer.level);
                this._playerModule.updateFashionFlyLv(cache.wardrobe.dealFlyLevel(arg1.flyLevel), arg1.miniPlayer.level);
                this._playerModule.vipInfoUpdate(arg1.miniPlayer.VIP);
                loc8 = arg1.fightSpiritLevel > 0 ? 1 : 0;
                this._playerModule.showFightSpirit(loc8);
                this._playerModule.updateFightSpirit(EquipmentUtil.getCurRolePackEquipsData(loc4), arg1.fightSpiritLevel, arg1.fightSpiritBreakLevel);
                this._playerModule.updateTitle();
                view.show();
                if (!view.isHide) 
                {
                    this._playerModule.checkTabBar();
                    this._playerModule.changeTabBarByIndex(0);
                }
            }
            return;
        }

        /* internal  */viewHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data as SEntityId;
            if (loc1.id != cache.role.entityInfo.entityId.id) 
            {
                this._isLookUp = true;
                loc2 = null;
                if (arg1.type == EventName.playerMenuLookPlayerInfo) 
                {
                    loc2 = this.tipsNotOnline;
                }
                GameProxy.playerInfoProxy.lookupRequest_async(cache.role.entityInfo.entityId, loc1, loc2);
            }
            return;
        }

        /* internal  */tipsNotOnline(arg1: SEntityId): void
        {
            MsgManager.showRollTipsMsg(Language.getString(30005));
            return;
        }

        /* internal  */onRoleLookupRuneHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            if (this._playerModule && this._playerModule.runeDescPanel.visible && loc1 == GModuleEvent.Mode_Other) 
            {
                this._playerModule.runeDescPanel.visible = false;
            }
            else if (this._playerModule && !this._playerModule.runeDescPanel.visible && loc1 == GModuleEvent.Mode_Other) 
            {
                this._playerModule.runeDescPanel.visible = true;
            }
            return;
        }

        private /* var */_playerModule: IPlayerModule;

        private /* var */_isLookUp: Boolean=false;
    }
